<!DOCTYPE html>
<html>
<#assign contextPath = request.contextPath/>
<head>
<meta charset="UTF-8">
<title></title>
<link href="${contextPath}/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript"
	src="${contextPath}/js/jquery-3.0.0.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
</head>

<body>
	<script>
		var msg = '${msg!}';
		var parammsg = '${Parameters.msg!}';
		if (msg != '') {
			toastr.info(msg);
		} else if (parammsg != '') {
			toastr.info(parammsg);
		}
	</script>
	<#include "/common/nav.html">
	<div class="container-fluid">
		<div class="row">
			<#include "/common/left_user.html">
			<div class="col-sm-9">
				<ol class="breadcrumb">
					<li class="active">主页</li>
				</ol>
				<div class="table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>分类</th>
								<th>投票名</th>
								<th>参与人数</th>
								<th>投票</th>
							</tr>
						</thead>
						<tbody>
							<#list p.list as v>
							<tr>
								<td>${p.startNum+v_index+1}</td>
								<td>${v.voteType.vtName!}</td>
								<td>${v.vtitle!}</td>
								<td>${v.vturnout!}</td>
								<td>
									<button type="button" class="btn btn-default btn-sm"
										data-toggle="modal" data-target="#exampleModal"
										data-whatever="${v.vid}">
										<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
										投票
									</button>
								</td>
							</tr>
							</#list>
						</tbody>
					</table>
					<nav aria-label="Page navigation" style="text-align: center">
						<ul class="pagination">
						 	<li <#if !p.hasPrev>class="disabled"</#if>><a<#if	p.hasPrev>href="usermainvote.action?p.pageNum=${p.pageNum-1}"</#if> aria-label="Previous"> <span aria-hidden="true">上一页</span></a></li> 
							<#list 1..p.pageSum as i>
							<li <#if p.pageNum == i>class="active"</#if>><a href="usermainvote.action?p.pageNum=${i}">${i}</a></li> 
							</#list>
							<li<#if !p.hasNext>class="disabled"</#if>>	<a<#if p.hasNext> href="usermainvote.action?p.pageNum=${p.pageNum+1}"</#if> 	aria-label="Next"> <span aria-hidden="true">下一页</span></a></li>
						</ul>
					</nav>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">×</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">投票标题</h4>
					<button id="fat-btn" class="btn btn-primary" type="button">投票类型
					</button>
				</div>
				<div class="modal-body">
					<form action="adduv.action" method="post" id="addfrom"></form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">提交</button>
				</div>
			</div>
		</div>
	</div>
	<script>
		$('#exampleModal').on('hidden.bs.modal', function() {
			$('#addfrom').submit();
		});
		$('#exampleModal')
				.on(
						'show.bs.modal',
						function(event) {
							var button = $(event.relatedTarget); // 触发事件的按钮  
							var whatever = button.data('whatever'); // 解析出data-whatever内容  
							var modal = $(this);
							$
									.post(
											"getvote.action",
											"id=" + whatever,
											function(r) {
												modal.find('.modal-title')
														.text(r.vtitle);
												modal.find("#fat-btn").text(
														r.voteType.vtName);
												var ops = r.voteOptions;
												var addform = modal
														.find('.modal-body #addfrom');
												addform.children().remove();
												addform
														.append("<input type='hidden' name='vid' value='"+whatever+"'/>");
												for (var i = 0; i < ops.length; i++) {
													var op = ops[i];
													var html = "<div class='radio'>";
													html += "<label>";
													html += "<input type='radio' name='oid' value='"
															+ op.voId + "' ";
													if (i == 0) {
														html += " checked ";
													}
													html += ">" + op.voText;
													html += "</label></div>"
													addform.append(html);
												}
											});
							//modal.find('.modal-body input').val(recipient)
						})
	</script>
</body>

</html>